﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using RooHui.Infrastructure.Entities.EFContext;
using RooHui.Infrastructure.Entities.Repository;
using RooHui.Infrastructure.Entities.Enum;

namespace RooHui.Infrastructure.Entities.Entity
{
    public class AmountOperation : IAccessible<P_AmountOperation, AmountOperation>, ILogicEntity<P_AmountOperation, AmountOperation>
    {
        public int ID { get; set; }
        /// <summary>
        /// 交易流水
        /// </summary>
        public string SequenceNO { get; set; }
        public string UserName { get; set; }
        public string Bank { get; set; }
        public decimal Amount { get; set; }
        public AmountOperationType OperationType { get; set; }
        /// <summary>
        /// 分账串
        /// </summary>
        public string SplitAmount { get; set; }
        public DateTime CreateTime { get; set; }
        /// <summary>
        /// 返回编码
        /// </summary>
        public string ResultCode { get; set; }
        /// <summary>
        /// 返回说明(返回串)
        /// </summary>
        public string ResultNote { get; set; }
        /// <summary>
        /// 返回流水号
        /// </summary>
        public string PaySequenceNo { get; set; }
        /// <summary>
        /// 支付返回时间
        /// </summary>
        public DateTime PayBackTime { get; set; }
        public bool IsSuccess { get; set; }
        public ItemStatus Status { get; set; }
        public string IpAddress { get; set; }
        public string Summary { get; set; }
        public string RefId { get; set; }

        protected override void Covariant(P_AmountOperation model)
        {
            if (model != null)
            {
                this.Amount = model.Amount;
                this.Bank = model.Bank;
                this.CreateTime = model.CreateTime;
                this.ID = model.ID;
                this.IpAddress = model.IpAddress;
                this.IsSuccess = model.IsSuccess;
                this.OperationType = (AmountOperationType)model.OperationType;
                this.PayBackTime = model.PayBackTime;
                this.PaySequenceNo = model.PaySequenceNo;
                this.ResultCode = model.ResultCode;
                this.ResultNote = model.ResultNote;
                this.SequenceNO = model.SequenceNO;
                this.SplitAmount = model.SplitAmount;
                this.Status = (ItemStatus)model.Status;
                this.UserName = model.UserName;
                this.Summary = model.Summary;
                this.RefId = model.RefId;
            }
        }

        protected override P_AmountOperation Inverter(AmountOperation model)
        {
            if (model != null)
            {
                return new P_AmountOperation()
                {
                    Amount = model.Amount,
                    Bank = model.Bank,
                    CreateTime = model.CreateTime,
                    ID = model.ID,
                    IpAddress = model.IpAddress,
                    IsSuccess = model.IsSuccess,
                    OperationType = (int)model.OperationType,
                    PayBackTime = model.PayBackTime,
                    PaySequenceNo = model.PaySequenceNo,
                    ResultCode = model.ResultCode,
                    ResultNote = model.ResultNote,
                    SequenceNO = model.SequenceNO,
                    SplitAmount = model.SplitAmount,
                    Status = (int)model.Status,
                    UserName = model.UserName,
                    Summary=model.Summary,
                    RefId=model.RefId
                };
            }
            return null;
        }

        public AmountOperation Set(P_AmountOperation dbModel)
        {
            Covariant(dbModel);
            return this;
        }
    }
}
